//
//  RowViewController.m
//  DevIPad
//
//  Created by HuCongshi on 15/11/16.
//  Copyright © 2015年 HuCongshi. All rights reserved.
//

#import "RowViewController.h"
#import "macro.h"
@interface RowViewController ()
@property (nonatomic, strong) NSArray *lists;
@property (nonatomic, strong) NSDictionary *currentBase;
@property (nonatomic, strong) NSDictionary *currentRoom;
@property (nonatomic, strong) NSArray *rows;
@property (nonatomic, strong) UITextView *rowDisText;
@property (nonatomic, strong) UILabel *rowDisLabel;
@end

@implementation RowViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self initData];
    [self initItems];
    // Do any additional setup after loading the view.
}
- (void) initData{
    NSBundle *bundle = [NSBundle mainBundle];
    NSString *plistPath = [bundle pathForResource:@"dev" ofType:@"plist"];
    self.lists = [[NSArray alloc] initWithContentsOfFile:plistPath];
    self.currentBase = [self.lists objectAtIndex:_baseID];
    NSArray *rooms = [[NSArray alloc] initWithArray:[self.currentBase objectForKey:@"rooms"]];
    self.currentRoom = [rooms objectAtIndex:_roomID];
    self.rows = [[NSArray alloc] initWithArray:[self.currentRoom objectForKey:@"rows"]];
    NSLogINFO(@"rows %lu",[self.rows count]);
}

- (void)initItems{
    CGRect rx = [UIScreen mainScreen].bounds;
    UIView *banner = [[UIView alloc] initWithFrame:CGRectMake(0, 0, rx.size.width, 130)];
    banner.backgroundColor = [UIColor blueColor];
    [self.view addSubview:banner];
    
    UIImageView *logo = [[UIImageView alloc] initWithFrame:CGRectMake(5,5,176,126)];
    logo.image = [UIImage imageNamed:@"logo.png"];
    [self.view addSubview:logo];
    
    UILabel *title = [[UILabel alloc] initWithFrame:CGRectMake(180, 30, 500, 80)];
    title.text = @"云资源管理系统";
    title.textColor = [UIColor whiteColor];
    title.font = [UIFont systemFontOfSize:36];
    title.textAlignment = NSTextAlignmentLeft;
    [self.view addSubview:title];
    
    UIView *vLine1 = [[UIView alloc] initWithFrame:CGRectMake(0, 190, rx.size.width, 2)];
    vLine1.backgroundColor = [UIColor blueColor];
    [self.view addSubview:vLine1];
    
    UIView *hLine = [[UIView alloc] initWithFrame:CGRectMake(rx.size.width/4.0, 192, 2, rx.size.height-192)];
    hLine.backgroundColor = [UIColor blueColor];
    [self.view addSubview:hLine];
    
    UIView *navi = [[UIView alloc] initWithFrame:CGRectMake(5, 135, 300, 50)];
    //navi.backgroundColor = [UIColor orangeColor];
    [self.view addSubview:navi];
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(backToHome:)];
    [navi addGestureRecognizer:tap];
    
    UIImageView *arrow = [[UIImageView alloc] initWithFrame:CGRectMake(0, 15, 60, 20)];
    arrow.image = [UIImage imageNamed:@"doublearrow.png"];
    [navi addSubview:arrow];
    
    UILabel *nameLabel = [[UILabel alloc] initWithFrame:CGRectMake(65, 5, 100, 40)];
    nameLabel.text = @"私有云";
    nameLabel.textColor = [UIColor blackColor];
    nameLabel.font = [UIFont systemFontOfSize:24];
    [navi addSubview:nameLabel];
    
    UIImageView *singleArrow = [[UIImageView alloc] initWithFrame:CGRectMake(150, 15, 30, 20)];
    singleArrow.image = [UIImage imageNamed:@"rightarrow.png"];
    [navi addSubview:singleArrow];
    
    UILabel *baseLabel = [[UILabel alloc] initWithFrame:CGRectMake(180, 5, 100, 40)];
    baseLabel.text = [self.currentBase objectForKey:@"name"];
    baseLabel.textColor = [UIColor blackColor];
    baseLabel.font = [UIFont systemFontOfSize:24];
    [navi addSubview:baseLabel];
    
    UIImageView *singleArrow2 = [[UIImageView alloc] initWithFrame:CGRectMake(290, 15, 30, 20)];
    singleArrow2.image = [UIImage imageNamed:@"rightarrow.png"];
    [navi addSubview:singleArrow2];
    
    UILabel *roomLabel = [[UILabel alloc] initWithFrame:CGRectMake(320, 5, 100, 40)];
    roomLabel.text = [self.currentRoom objectForKey:@"roomname"];
    roomLabel.textColor = [UIColor blackColor];
    roomLabel.font = [UIFont systemFontOfSize:24];
    [navi addSubview:roomLabel];
    
    UILabel *roomDisLabel = [[UILabel alloc] initWithFrame:CGRectMake(rx.size.width/4.0+10, 197, 200, 40)];
    roomDisLabel.text = [self.currentRoom objectForKey:@"roomname"];
    roomDisLabel.font = [UIFont systemFontOfSize:28];
    roomDisLabel.textColor = [UIColor blackColor];
    [self.view addSubview:roomDisLabel];
    
    UITextView *roomDisText = [[UITextView alloc] initWithFrame:CGRectMake(rx.size.width/4.0+10, 240, rx.size.width/4.0*3-80, (rx.size.height-250)/2.0-20)];
    //roomDisText.backgroundColor = [UIColor orangeColor];
    roomDisText.editable = NO;
    roomDisText.scrollEnabled = YES;
    roomDisText.textColor = [UIColor blackColor];
    roomDisText.text = [self.currentRoom objectForKey:@"roomdiscription"];
    roomDisText.font = [UIFont systemFontOfSize:20];
    [self.view addSubview:roomDisText];
    
    UIView *hLine2 = [[UIView alloc] initWithFrame:CGRectMake(rx.size.width/4.0, 192+(rx.size.height-192)/2.0, rx.size.width/4.0*3, 2)];
    hLine2.backgroundColor = [UIColor blueColor];
    [self.view addSubview:hLine2];
    
    self.rowDisLabel = [[UILabel alloc] initWithFrame:CGRectMake(rx.size.width/4.0+10, 197+(rx.size.height-192)/2.0, 200, 40)];
    //rowDisLabel.text = [self.currentRoom objectForKey:@"roomname"];
    self.rowDisLabel.font = [UIFont systemFontOfSize:28];
    self.rowDisLabel.textColor = [UIColor blackColor];
    [self.view addSubview:self.rowDisLabel];
    
    self.rowDisText = [[UITextView alloc] initWithFrame:CGRectMake(rx.size.width/4.0+10, 240+(rx.size.height-192)/2.0, rx.size.width/4.0*3-80, (rx.size.height-250)/2.0-20)];
    //rowDisText.backgroundColor = [UIColor orangeColor];
    self.rowDisText.editable = NO;
    self.rowDisText.scrollEnabled = YES;
    self.rowDisText.textColor = [UIColor blackColor];
    //rowDisText.text = [self.currentRoom objectForKey:@"roomdiscription"];
    self.rowDisText.font = [UIFont systemFontOfSize:20];
    [self.view addSubview:self.rowDisText];
    
    
    UITableView *rowsTableView = [[UITableView alloc] initWithFrame:CGRectMake(5, 197, rx.size.width/4.0-10, rx.size.height-210)];
    rowsTableView.delegate = self;
    rowsTableView.dataSource = self;
    [self.view addSubview:rowsTableView];
    
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
-(void)backToHome:(UITapGestureRecognizer*)recongizer{
    NSLogINFO(@"Tap");
    [self.navigationController popViewControllerAnimated:YES];
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/
#pragma mark -UITableView
-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *cellIdentifier = @"CellIdentifier";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
    }
    
    NSUInteger row = [indexPath row];
    NSDictionary *base = [self.rows objectAtIndex:row];
    cell.textLabel.text = [base objectForKey:@"rowname"];
    cell.textLabel.font = [UIFont systemFontOfSize:18];
    cell.textLabel.textColor = [UIColor blackColor];
    return cell;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return [self.rows count];
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    NSUInteger row = [indexPath row];
    NSDictionary *base = [self.rows objectAtIndex:row];
    self.rowDisLabel.text = [base objectForKey:@"rowname"];
    self.rowDisText.text = [base objectForKey:@"rowdiscription"];
}
@end
